package com.gengral.commons.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        Object gmtCreateBy = getFieldValByName("gmtCreateBy", metaObject);
        Object gmtCreateTime = getFieldValByName("gmtCreateTime", metaObject);
        setFieldValByName("gmtCreateBy","sht", metaObject);
        setFieldValByName("gmtCreateTime",LocalDateTime.now(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        Object gmtModifiedBy = getFieldValByName("gmtModifiedBy", metaObject);
        Object gmtModifiedTime = getFieldValByName("gmtModifiedTime", metaObject);
        setFieldValByName("gmtModifiedBy","sht", metaObject);
        setFieldValByName("gmtModifiedTime",LocalDateTime.now(), metaObject);
    }
}
